#!/bin/bash

#
# Do not run coverage for forks as most people do not have extra tools enabled
# for their fork. Avoid it also for release builds as that can fail such
# build unnecessarily.
#

if [[ -n $OPENGROK_REF && $OPENGROK_REF == refs/heads/* ]]; then
	OPENGROK_BRANCH=${OPENGROK_REF#"refs/heads/"}
fi

extra_args=""
if [[ "x$OPENGROK_REPO_SLUG" == "xoracle/opengrok" && "x$OPENGROK_BRANCH" == "xmaster" ]]; then
	echo "Enabling Coveralls"
	if [[ -n $OPENGROK_COVERALLS_TOKEN ]]; then
		extra_args="$extra_args -DrepoToken=$OPENGROK_COVERALLS_TOKEN"
	fi
	extra_args="$extra_args jacoco:report coveralls:report"

	#
	# Sonar seems to only work on master branch commits.
	#
	if [[ -z "${OPENGROK_PULL_REQUEST}" ]]; then
		echo "Enabling Sonar"
		extra_args="$extra_args -P sonar -Dsonar.login=$OPENGROK_SONAR_TOKEN sonar:sonar"
	fi
fi

./mvnw -B -V verify $extra_args
